package com.avic.modules.quartz.task;

import com.avic.modules.backup4MySQL.MySQLBackup;
import com.avic.modules.log.domain.vo.LogEnumeration;
import com.avic.modules.log.domain.vo.LogVo;
import com.avic.modules.log.service.LogsService;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.sql.SQLException;

@Component
public class MySQLBackupTask {

    private final MySQLBackup backup;
    private final LogsService logsService;

    public MySQLBackupTask(MySQLBackup backup, LogsService logsService) {
        this.backup = backup;
        this.logsService = logsService;
    }

    public void runMySQLDump() throws SQLException, IOException, ClassNotFoundException {
        backup.exportSQL();
        // 创建操作日志信息
        LogVo logVo = new LogVo();
        String name = "[自动备份]了" + "[数据库信息]";
        logVo.setBehavior(name);
        logVo.setAction(LogEnumeration.Autobackup.getMessage());
        logsService.sysAdminSave(logVo);
    }
    
}
